package com.example.basic.googleAPI;

import java.util.ArrayList;

public class Test {

    /**
     * 目标是为了检测 google 判断危险网站API的有效性 和  准确性
     *
     */

    public static void main(String[] args) {

        boolean isCustomTest = false;
        String api_key = "AIzaSyDmeXw5OMIjyiYv0L17C9LEF-5QsMVoP_A"; //这里放你的api_key
        String apiUrl = "https://safebrowsing.googleapis.com/v4/threatMatches:find?key=" + api_key;

        ArrayList<String> feedList = FileUtils.getFeedList();

        if (isCustomTest) {
            feedList.clear();
            feedList.add("https://www.uni-transaktion.com/");
            feedList.add("http://eventggff-news1.duckdns.org/");
            feedList.add("http://shifawll1.ae/post/2/smogalldomainn/updates.htm");
            feedList.add("http://namastemaryland.com/file/fax/");
            feedList.add("http://marketplace.facebook.com-ifwfkouvn.isiolo.go.ke/profile.html?countUser=865b28ef520153233dd1dbbfc9a7860c");
            feedList.add("https://messagerie-vocale262.yolasite.com/");
            feedList.add("http://ttf.tf/RpIcn");
            feedList.add("https://whatsapp.group18plus.se.ke/");
            feedList.add("http://kusvjbmjfaiu.vgstbx.cn/instagram-me");
            feedList.add("http://www.chatwhatsapgrubinvit.duckdns.org/");
            feedList.add("https://www.facebook.homelisting-realestate-id19372311.com/");
            feedList.add("https://www.facebook.homelisting-realestate-id19372311.com");
        }

//        int sum = feedList.size();
//        int safeNum = 0;
//        int dangerousNum = 0;
//        long startTime = System.currentTimeMillis();
        for (String s : feedList) {
            String result = HttpClient.doPost(apiUrl, GsonUtil.getRequestApiBodyJsonStr(s));
            if ("{}".equals(result.trim())) {
                System.out.println(" url: " + s + "  不是危险网站");
            } else {
                System.out.println(" url: " + s + "  是危险网站");
            }
        }
//        String result = doPost(apiUrl, GsonUtil.getRequestApiBodyJsonStr(feedList));
//        System.out.println(result);
//        if ("{}".equals(result)) {
//            safeNum++;
//        } else {
//            dangerousNum++;
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println(
//                        "测试结果：\n" +
//                        "检测网站总数为：" + sum + "\n" +
//                        "开始时间为：" + startTime + "\n" +
//                        "结束时间为：" + endTime + "\n" +
//                        "检测总时长：" + (endTime - startTime) + " ms \n" +
//                        "安全网站总数：" + safeNum + " ; 危险网站总数：" + dangerousNum
//        );
    }

}
